#

if grep -Eq 'Focal Fossa' /etc/issue || grep -Eq 'Focal Fossa' /etc/*-release
then
  echo 'linux is ubuntu2004'
  if [ -h /usr/bin/pwsh ]
  then
    echo 'powershell installed on ubuntu2004'
    if grep -Eq 'powershell' /etc/ssh/sshd_config
    then
      echo 'powershell_sshd_good'
      exit 0
    else
      echo '' >>  /etc/ssh/sshd_config
      echo 'Subsystem powershell /usr/bin/pwsh -sshs -NoLogo -NoProfile' >>  /etc/ssh/sshd_config
      echo 'UseDNS no' >>  /etc/ssh/sshd_config
      echo 'PermitRootLogin yes' >>  /etc/ssh/sshd_config
      systemctl restart sshd.service
      echo 'powershell_sshd_fixed'
      exit 0
    fi
  else
    echo 'installing powershell now'
    sudo snap remove powershell
    sudo curl -o /tmp/a.deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/pool/main/o/openssl1.0/libssl1.0.0_1.0.2n-1ubuntu5.3_amd64.deb
    sudo dpkg -i /tmp/a.deb
    sudo curl -o /tmp/b.deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/pool/main/i/icu/libicu60_60.2-3ubuntu3.1_amd64.deb
    sudo dpkg -i /tmp/b.deb
    sudo curl -o /tmp/p.deb https://packages.microsoft.com/ubuntu/18.04/prod/pool/main/p/powershell/powershell_7.0.3-1.ubuntu.18.04_amd64.deb
    sudo dpkg -i /tmp/p.deb
    apt update
    apt --fix-broken install liblttng-ust0 liblttng-ust-ctl4
    echo 'install powershell sucess'
    if grep -Eq 'powershell' /etc/ssh/sshd_config
    then
      echo 'powershell_sshd_good'
      exit 0
    else
      echo '' >>  /etc/ssh/sshd_config
      echo 'Subsystem powershell /usr/bin/pwsh -sshs -NoLogo -NoProfile' >>  /etc/ssh/sshd_config
      echo 'UseDNS no' >>  /etc/ssh/sshd_config
      echo 'PermitRootLogin yes' >>  /etc/ssh/sshd_config
      systemctl restart sshd.service
      echo 'powershell_sshd_fixed'
      exit 0
    fi
  fi
else
  echo 'linux not ubuntu2004'
  exit 2
fi




